//
//  SPVTipViewController.swift
//  ezyform
//
//  Created by MoennigQ on 24/6/19.
//  Copyright © 2019 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SnapKit
class JobDetailSPVTipView: View {
    var learnMoreClosure: (()->Void)?
    override func setUpView() {
        self.backgroundColor = UIColor.black.withAlphaComponent(0.8)
        //back view
        let backView = UIView()
        backView.backgroundColor = UIColor.white
        self.addSubview(backView)
        backView.layer.cornerRadius = Constant.BackViewCornerRadius
        backView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.height.greaterThanOrEqualTo(0)
            make.center.equalToSuperview()
        }
        //titile
        let titleLabel = ContentLabel(R.font.interMedium(size: 15))
        titleLabel.text = NSLocalizedString("pvd.detail.spv.tip", comment: "")
        titleLabel.numberOfLines = 0
        titleLabel.textAlignment = NSTextAlignment.left
        
        backView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.top.left.equalTo(24)
            make.right.equalTo(-24)
            make.height.greaterThanOrEqualTo(0)
        }
        
        //titile
        let learnMoreLabel = ContentLabel(R.font.interMedium(size: 15),hexStr: "#379657")
        learnMoreLabel.text = NSLocalizedString("pvd.detail.spv.leanrmore", comment: "")
        learnMoreLabel.numberOfLines = 0
        learnMoreLabel.isUserInteractionEnabled = true
        backView.addSubview(learnMoreLabel)
        learnMoreLabel.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(10)
            make.left.equalToSuperview().offset(20)
            make.width.height.greaterThanOrEqualTo(0)
        }
        //right arrow
        let learnMoreRightArrow = UIImageView(image: UIImage(named: "installation_detail_spv_tip_right_arrow"))
        backView.addSubview(learnMoreRightArrow)
        learnMoreRightArrow.snp.makeConstraints { (make) in
            make.left.equalTo(learnMoreLabel.snp.right)
            make.centerY.equalTo(learnMoreLabel)
            make.height.width.equalTo(24)
        }
        //
        //horizonal line view
        let lineView = View(hexStr: "#0000001A")
        backView.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.top.equalTo(learnMoreLabel.snp.bottom).offset(24)
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        
        //ok button
        let okBtn = ViewFactory.shared.generateButtonOnAlertView(R.string.localizable.oK())
        backView.addSubview(okBtn)
        okBtn.snp.makeConstraints { (make) in
            make.top.equalTo(lineView.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(48)
            make.bottom.equalToSuperview()
        }
        okBtn.addTarget(self, action: #selector(okBtnClick), for: UIControl.Event.touchUpInside)
        let tapBGesture = UITapGestureRecognizer(target: self, action: #selector(learnMoreClick))
        learnMoreLabel.addGestureRecognizer(tapBGesture)
    }
    @objc
    func okBtnClick(){
        self.removeFromSuperview()
    }
    @objc
    func learnMoreClick(){
        self.removeFromSuperview()
        self.learnMoreClosure?()
    }
}
